﻿using Microsoft.EntityFrameworkCore;
using Models.Common;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using UtilsBase;
using UtilsCache;
using UtilsORM;
using UtilsORM.MySqlData;
using static Models.Common.EnumDeviceModelType;
////using System.Web.Script.Serialization;

namespace GatewayServerService.Data
{
    public class DBIotDeviceModelTypeCache
    {

        public iot_device_model_type getModelTypeCache(string tguid)
        {
            //UtilRedisNewLife UtilRedisNewLife = UtilRedisNewLife;         
            iot_device_model_type list = UtilMemoryCacheHelper.get<iot_device_model_type>("getModelType" + tguid);//数据太多，报错
            if (list == null)
            {
                EFYihongIotContext ef = new EFYihongIotContext();
                list = ef.iot_device_model_type.Where(c => c.t_status == 0 && c.t_guid == tguid).FirstOrDefault();
                UtilMemoryCacheHelper.set("getModelType" + tguid, list);
            }
            return list;
        }
        public iot_device_model_type getModelTypeByDeviceCache(string dguid)
        {
            //UtilRedisNewLife UtilRedisNewLife = UtilRedisNewLife;
            iot_device_model_type model_Type = UtilMemoryCacheHelper.get<iot_device_model_type>("getModelTypeByDeviceCache" + dguid);//数据太多，报错
            if (model_Type == null)
            {

                EFYihongIotContext ef = new EFYihongIotContext();
                iot_device_model getModel = new DBIotDeviceModelCache().getModelByDeviceCache(dguid);
                model_Type = new DBIotDeviceModelTypeCache().getModelTypeCache(getModel.m_type_guid);
                UtilMemoryCacheHelper.set("getModelTypeByDeviceCache" + dguid, model_Type, 60);
            }
            return model_Type;
        }
    }
}
